package com.book.utils;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;



@Component
public class SendMailTool {

    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String from;
    
    public void SendMail(String toEmail, String captcha) {

        //创建SimpleMailMessage对象，用于邮件发送
        SimpleMailMessage mailMessage = new SimpleMailMessage();
        mailMessage.setFrom(from);
        mailMessage.setTo(toEmail);
        mailMessage.setSubject("风语书城邮箱验证");//标题

        String text = "您的验证码为："+ captcha + "。请注意，本次验证码有效时间为5分钟。请勿回复，感谢您的使用。";
        //文本内容
        mailMessage.setText(text);

        javaMailSender.send(mailMessage);
    }
}
